<template>
  <div class="information-page">
    <BaseHeader
      :navs="navs"
      :activeNav="activeNav"
      @nav-change="handleNavChange"
    />
    <div class="information-title">
      <div class="link">首页 > <a>资料</a></div>
    </div>
    <div class="inforType">
      <div>资料类型</div>
      <div class="top-tabs">
        <div
          class="tab-item"
          :class="{ active: activeTab === 'free' }"
          @click="activeTab = 'free'"
        >
          免费资料区
          <!-- v-if="activeTab === 'free' || hoverTab === 'free'" -->
          <span class="tab-badge">729</span>
        </div>
        <div
          class="tab-item"
          :class="{ active: activeTab === 'vip' }"
          @click="activeTab = 'vip'"
          @mouseenter="hoverTab = 'vip'"
          @mouseleave="hoverTab = ''"
        >
          学员资料专区
          <span class="tab-vip">学员专用</span>
        </div>
      </div>
    </div>
    <div class="main-content">
      <!-- 左侧栏 -->
      <div class="sidebar">
        <div
          v-for="item in sidebarList"
          :key="item"
          :class="['sidebar-item', { active: item === activeSidebar }]"
          @click="handleSidebarChange(item)"
        >
          {{ item }}
        </div>
      </div>
      <!-- 右侧内容 -->
      <div class="information-content">
        <div class="information-list">
          <div class="info-item" v-for="item in pagedList" :key="item.id">
            <img src="@/assets/index/pdf.png" class="pdf-icon" />
            <div class="info-detail">
              <div class="info-title">{{ item.title }}</div>
              <div class="info-meta">
                <span>免费</span>
                <span>{{ item.size }}</span>
                <span>{{ item.type }}</span>
              </div>
            </div>
            <button class="download-btn" @click="showDialog = true">
              下载
            </button>
          </div>
        </div>
        <!-- 分页 -->
        <div class="pagination">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="filteredList.length"
            :page-size="pageSize"
            :current-page="currentPage"
            @current-change="handlePageChange"
          />
        </div>
      </div>
    </div>
    <BaseFooter />
    <div v-if="showDialog" class="vip-dialog-mask">
      <div class="vip-dialog">
        <img src="@/assets/index/nomore.png" class="dialog-top-img" />
        <div class="dialog-msg">
          很抱歉您还未购买相应课程，无法查看相关资料哦！
        </div>
        <div class="dialog-btns">
          <button class="btn-cancel" @click="showDialog = false">取 消</button>
          <button class="btn-buy" @click="goBuy">去购买</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import BaseHeader from "@/components/baseHeader.vue";
import BaseFooter from "@/components/baseFooter.vue";
export default {
  name: "Information",
  components: { BaseHeader, BaseFooter },
  data() {
    return {
      navs: ["首页", "新闻", "题库", "资料", "产教课程"],
      activeNav: "资料",
      sidebarList: ["知识科普", "赛事讲解", "人工智能", "行业动态", "AI工具"],
      activeSidebar: "知识科普",
      infoList: [
        // 这里填充你的资料数据
        {
          id: 1,
          title: "2025上半年信息系统项目管理师 考前30天冲刺计划.pdf",
          size: "1.5MB",
          type: "pdf文件",
        },
        {
          id: 2,
          title: "2025上半年信息系统项目管理师 考前30天冲刺计划.pdf",
          size: "1.5MB",
          type: "pdf文件",
        },
        {
          id: 2,
          title: "2025上半年信息系统项目管理师 考前30天冲刺计划.pdf",
          size: "1.5MB",
          type: "pdf文件",
        },
        {
          id: 2,
          title: "2025上半年信息系统项目管理师 考前30天冲刺计划.pdf",
          size: "1.5MB",
          type: "pdf文件",
        },
      ],
      currentPage: 1,
      pageSize: 7,
      activeTab: "free", // 当前选中的tab
      hoverTab: "",
      showDialog: false, // 控制弹框显示
    };
  },
  computed: {
    filteredList() {
      // 根据activeSidebar过滤数据
      return this.infoList; // 这里可以根据实际需求过滤
    },
    pagedList() {
      const start = (this.currentPage - 1) * this.pageSize;
      return this.filteredList.slice(start, start + this.pageSize);
    },
  },
  methods: {
    handleNavChange(nav) {
      this.activeNav = nav;
      // 这里可以根据nav切换内容
    },
    handleSidebarChange(item) {
      this.activeSidebar = item;
      this.currentPage = 1;
      // 这里可以根据item切换内容
    },
    handlePageChange(page) {
      this.currentPage = page;
    },
    goBuy() {
      // 跳转购买页面逻辑
      this.showDialog = false;
      // 例如：this.$router.push('/buy');
    },
  },
};
</script>
<style scoped lang="scss">
.information-title {
  width: 100%;
  height: 106px;
  background: linear-gradient(180deg, #f6f4fe 0%, #ffffff 100%);
  font-weight: 500;
  font-size: 14px;
  color: #41464f;
  padding-top: 23px;
  a {
    color: #1664ff;
  }
  .link {
    width: 1200px;
    margin: 0 auto;
    text-align: left;
  }
}
.main-content {
  display: flex;
  width: 1200px;
  margin: 0 auto;
}
.sidebar {
  width: 180px;
  background: #fff;
  border-right: 1px solid #f0f0f0;
  .sidebar-item {
    padding: 12px 40px;
    font-size: 16px;
    color: #222;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    &.active {
      color: #222;
      font-weight: 600;
      background: #f7f8fa;
      &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        width: 4px;
        height: 100%;
        background: #222;
        border-radius: 2px;
      }
    }
  }
}
.information-content {
  flex: 1;
  padding: 0 40px;
}
.inforType {
  width: 1200px;
  margin: 0 auto;
  text-align: left;
  font-weight: 500;
  font-size: 18px;
  color: #0c0d0e;
  display: flex;
  margin-top: -20px;
}
.information-list {
  width: 900px;

  .info-item {
    display: flex;
    align-items: center;
    background: #fff;
    margin-bottom: 24px;
    box-shadow: 0px 2px 12px 0px #e1e3eb;
    border-radius: 12px;
    border: 1px solid #ffffff;
    margin-bottom: 20px;
    padding-bottom: 20px;
    .pdf-icon {
      width: 72px;
      height: 72px;
      margin-right: 32px;
      margin-top: 20px;
      margin-left: 20px;
    }
    .info-detail {
      flex: 1;
      text-align: left;
      .info-title {
        font-size: 18px;
        font-weight: 600;
        color: #222;
        margin-bottom: 12px;
      }
      .info-meta {
        color: #888;
        font-size: 14px;
        span {
          margin-right: 18px;
          background: #f5f5f5;
          border-radius: 4px;
          padding: 2px 8px;
        }
        span:first-child {
          color: #1664ff;
          background: #eaf2ff;
        }
      }
    }
    .download-btn {
      background: #1664ff;
      color: #fff;
      border: none;
      border-radius: 8px;
      padding: 12px 40px;
      font-size: 18px;
      font-weight: 500;
      cursor: pointer;
      transition: background 0.2s;
      margin-right: 30px;
      margin-top: 20px;
      &:hover {
        background: #0056d6;
      }
    }
  }
}
.pagination {
  text-align: center;
  margin: 24px 0;
}
.header-nav-item {
  font-size: 18px;
  color: #888;
  padding: 0 24px;
  cursor: pointer;
  position: relative;
  &.active {
    color: #222;
    font-weight: 700;
    &::after {
      content: "";
      display: block;
      width: 100%;
      height: 3px;
      background: #222;
      border-radius: 2px;
      position: absolute;
      left: 0;
      bottom: -8px;
    }
  }
}
.top-tabs {
  display: flex;
  align-items: center;
  margin-bottom: 32px;
  margin-left: 150px;
  .tab-item {
    font-weight: 600;
    font-size: 20px;
    color: #0c0d0e;
    margin-right: 32px;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: color 0.2s;
    &.active {
      font-weight: 700;
      color: #222;
      // &::after {
      //   content: "";
      //   display: block;
      //   width: 100%;
      //   height: 3px;
      //   background: #222;
      //   border-radius: 2px;
      //   position: absolute;
      //   left: 0;
      //   bottom: -8px;
      // }
    }
    &:not(.active) {
      color: #888;
    }
    .tab-badge {
      margin-left: 8px;
      font-size: 14px;
      background: #f5f5f5;
      color: #888;
      border-radius: 12px;
      padding: 2px 10px;
      font-weight: 400;
      position: relative;
      top: 0px;
    }
    .tab-vip {
      margin-left: 8px;
      font-size: 14px;
      background: #1664ff;
      color: #fff;
      border-radius: 12px;
      padding: 2px 12px;
      font-weight: 400;
      position: relative;
      top: 0px;
    }
  }
}
.vip-dialog-mask {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.15);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.vip-dialog {
  width: 480px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
  padding: 40px 32px 32px 32px;
  text-align: center;
  position: relative;
}
.dialog-top-img {
  width: 120px;
  margin-bottom: 16px;
  margin-top: -40px;
}
.dialog-msg {
  font-size: 20px;
  color: #222;
  font-weight: 600;
  margin-bottom: 36px;
  margin-top: 8px;
}
.dialog-btns {
  display: flex;
  justify-content: center;
  gap: 24px;
  .btn-cancel {
    width: 120px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid #e5e6eb;
    background: #fff;
    color: #888;
    font-size: 16px;
    cursor: pointer;
    transition: border 0.2s;
    &:hover {
      border: 1px solid #1664ff;
    }
  }
  .btn-buy {
    width: 120px;
    height: 44px;
    border-radius: 8px;
    border: none;
    background: #1664ff;
    color: #fff;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    &:hover {
      background: #0056d6;
    }
  }
}
</style>
